def is_prime(n):
    F=True
    for i in range (2,int(n**0.5)+1):
        if n%i==0:
            F=False
            break
    return(F)

number=''
x=input()
word=x.split()

for i in range (len(word)):
    if word[i]=="zero": number+='0'
    if word[i]=="one": number+='1'
    if word[i]=="two": number+='2'
    if word[i]=="three": number+='3'
    if word[i]=="four": number+='4'
    if word[i]=="five": number+='5'
    if word[i]=="six": number+='6'
    if word[i]=="seven": number+='7'
    if word[i]=="eight": number+='8'
    if word[i]=="nine": number+='9'
if number != '': 
    number = int(number)
else:
    number = 0
spis=[]
for i in range (100,999+1):
    if is_prime(i)==True:
        spis.append(i)
if number < 100 or number > 999 or len(word) != 3:
    print("Wrong input")
else:
    min_r=1000000
    for i in range(len(spis)):
        if abs(number-spis[i])<=min_r:
            min_r=abs(number-spis[i])
            min_n=i
    print(spis[min_n])
